package com.wxlsoft.ui;


import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Arrays;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

import com.wxlsoft.excel.enums.HandlerType;
import com.wxlsoft.ui.conflist.XmlFileChooseListener;
import com.wxlsoft.utils.UIContext;

/**
 * @author wangxiaoliang
 */
public class UiController extends JFrame {
	
	private static final long serialVersionUID = 1L;
	
	public UiController() {
		initComponents();
		closeAction();	// TODO change
		UIContext.register(this);
	}
	
	// TODO change
	private void closeAction() {
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
			    System.exit(0);   
			} 
		});
	}	

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
		dialogPane = new JPanel();
		contentPanel = new JPanel();
		tabbedPane1 = new JTabbedPane();
		
		toolBar1 = new JToolBar("extract");
		panel2 = new JPanel();
		panel11 = new JPanel();
		button2 = new JButton();
		
		label3 = new JLabel();
		panel12 = new JPanel();
		scrollPane2 = new JScrollPane();
		textPane1 = new JTextPane();
		
		toolBar3 = new JToolBar("convert");
		panel3 = new JPanel();
		panel13 = new JPanel();
		button3 = new JButton();
		label4 = new JLabel();
		panel14 = new JPanel();
		scrollPane3 = new JScrollPane();
		textPane2 = new JTextPane();
		
		toolBar4 = new JToolBar("importConfig");
		panel5 = new JPanel();
		tabbedPane2 = new JTabbedPane();
		toolBar5 = new JToolBar("esb");
		panel6 = new JPanel();
		panel7 = new JPanel();
		label5 = new JLabel();
		button4 = new JButton();
		panel15 = new JPanel();
		panel17 = new JPanel();
		label7 = new JLabel();
		
		apolloPortal = new JTextField();
		apolloPortal.setText("http://10.5.181.215:9090");
		
		label8 = new JLabel();
		apolloEnv = new JTextField();
		apolloEnv.setText("dev");
		
		panel16 = new JPanel();
		apolloUsername = new JTextField();
		apolloUsername.setText("admin");
		
		label1 = new JLabel();
		label2 = new JLabel();
		apolloPassword = new JPasswordField();
		apolloPassword.setText("i0QTKZLajHV1SvS4ahk8cQ==");
		
		scrollPane4 = new JScrollPane();
		textPane4 = new JTextPane();
		toolBar6 = new JToolBar("service");
		
		toolBar2 = new JToolBar("about");
		panel1 = new JPanel();
		scrollPane1 = new JScrollPane();
		textPane3 = new JTextPane();
		buttonBar = new JPanel();
		
		// TODO change
		progressBar1 = new JProgressBar(0, 500);
		progressBar1.setName("progress");
		
		okButton = new JButton();
		cancelButton = new JButton();

		//======== this ========
		setForeground(new Color(0x9999ff));
		setTitle("ESB\u5b9e\u65bd\u8f85\u52a9\u5de5\u5177");
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		//======== dialogPane ========
		{
			dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
			dialogPane.setLayout(new BorderLayout());

			//======== contentPanel ========
			{
				contentPanel.setLayout(new CardLayout());

				//======== tabbedPane1 ========
				{

					//======== toolBar1 ========
					{

						//======== panel2 ========
						{
							panel2.setLayout(new GridLayout(2, 0));

							//======== panel11 ========
							{
								panel11.setLayout(null);

								//---- button2 ----
								button2.setText("\u9009\u62e9\u6587\u4ef6");
								panel11.add(button2);
								button2.setBounds(705, 30, 115, 40);
								// TODO change
								button2.addActionListener(new ExcelFileChooseListener(label3, chooser));
								
								//---- label3 ----
								label3.setText("\u8bf7\u9009\u62e9\u6587\u4ef6...");
								label3.setBorder(LineBorder.createBlackLineBorder());
								panel11.add(label3);
								label3.setBounds(20, 30, 660, 40);

								{
									// compute preferred size
									Dimension preferredSize = new Dimension();
									for(int i = 0; i < panel11.getComponentCount(); i++) {
										Rectangle bounds = panel11.getComponent(i).getBounds();
										preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
										preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
									}
									Insets insets = panel11.getInsets();
									preferredSize.width += insets.right;
									preferredSize.height += insets.bottom;
									panel11.setMinimumSize(preferredSize);
									panel11.setPreferredSize(preferredSize);
								}
							}
							panel2.add(panel11);

							//======== panel12 ========
							{
								panel12.setLayout(null);

								//======== scrollPane2 ========
								{

									//---- textPane1 ----
									textPane1.setText("\u6ce8\u610f\u4e8b\u9879\uff1a\n\u5f53\u524d\u5de5\u5177\u53ea\u9002\u7528\u4e8e\u4e4c\u9c81\u6728\u9f50\u94f6\u884c\u6838\u5fc3\u63a5\u53e3\u5b57\u6bb5\u63d0\u53d6\n\n\u4f7f\u7528\u65b9\u6cd5\uff1a\n1\u3001\u70b9\u51fb\u9009\u62e9\u6587\u4ef6\u6309\u94ae\uff0c\u9009\u62e9\u9700\u8981\u63d0\u53d6\u7684 excel \u6587\u4ef6\n2\u3001\u70b9\u51fb\u9875\u9762 OK\n3\u3001\u7b49\u5f85\u8fdb\u5ea6\u6761\u6267\u884c\u5b8c\u6210\uff0c\u6210\u529f\u8fdb\u5ea6\u6761\u663e\u793a\u7eff\u8272\uff0c\u53cd\u4e4b\u7ea2\u8272\n4\u3001\u751f\u6210\u7684\u6587\u4ef6\u4e0e\u6e90\u6587\u4ef6\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\uff0c\u5e76\u901a\u8fc7\u6e90\u6587\u4ef6\u540d_\u6570\u5b57\u6807\u8bb0");
									textPane1.setEditable(false);
									textPane1.setBackground(new Color(0x00cccc));
									scrollPane2.setViewportView(textPane1);
								}
								panel12.add(scrollPane2);
								scrollPane2.setBounds(15, 10, 805, 170);

								{
									// compute preferred size
									Dimension preferredSize = new Dimension();
									for(int i = 0; i < panel12.getComponentCount(); i++) {
										Rectangle bounds = panel12.getComponent(i).getBounds();
										preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
										preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
									}
									Insets insets = panel12.getInsets();
									preferredSize.width += insets.right;
									preferredSize.height += insets.bottom;
									panel12.setMinimumSize(preferredSize);
									panel12.setPreferredSize(preferredSize);
								}
							}
							panel2.add(panel12);
						}
						toolBar1.add(panel2);
					}
					tabbedPane1.addTab("\u6838\u5fc3\u63a5\u53e3\u5b57\u6bb5\u63d0\u53d6", toolBar1);

					//======== toolBar3 ========
					{

						//======== panel3 ========
						{
							panel3.setLayout(new GridLayout(2, 0));

							//======== panel13 ========
							{
								panel13.setLayout(null);

								//---- button3 ----
								button3.setText("\u9009\u62e9\u6587\u4ef6");
								panel13.add(button3);
								button3.setBounds(705, 30, 115, 40);
								// TODO change
								button3.addActionListener(new ExcelFileChooseListener(label4, chooser));
								
								//---- label4 ----
								label4.setText("\u8bf7\u9009\u62e9\u6587\u4ef6...");
								label4.setBorder(LineBorder.createBlackLineBorder());
								panel13.add(label4);
								label4.setBounds(20, 30, 660, 40);

								{
									// compute preferred size
									Dimension preferredSize = new Dimension();
									for(int i = 0; i < panel13.getComponentCount(); i++) {
										Rectangle bounds = panel13.getComponent(i).getBounds();
										preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
										preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
									}
									Insets insets = panel13.getInsets();
									preferredSize.width += insets.right;
									preferredSize.height += insets.bottom;
									panel13.setMinimumSize(preferredSize);
									panel13.setPreferredSize(preferredSize);
								}
							}
							panel3.add(panel13);

							//======== panel14 ========
							{
								panel14.setLayout(null);

								//======== scrollPane3 ========
								{

									//---- textPane2 ----
									textPane2.setText("\u6ce8\u610f\u4e8b\u9879\uff1a\n1\u3001\u5f53\u524d\u5de5\u5177\u53ea\u9002\u7528\u4e8e\u4e4c\u9c81\u6728\u9f50\u94f6\u884c\u6838\u5fc3\u63a5\u53e3\u5b57\u6bb5\u8f6c\u6362\n2\u3001\u672c\u5de5\u5177\u5df2\u540c\u65f6\u652f\u6301 xls\u3001xlsx\u4e24\u79cd\u7c7b\u578b\u7684\u6e90\u6587\u4ef6\uff0c\u6700\u540e\u4ec5\u751f\u6210 xlsx \u76ee\u6807\u6587\u4ef6\n\n\u4f7f\u7528\u65b9\u6cd5\uff1a\n1\u3001\u70b9\u51fb\u9009\u62e9\u6587\u4ef6\u6309\u94ae\uff0c\u9009\u62e9\u9700\u8981\u63d0\u53d6\u7684 excel \u6587\u4ef6\n2\u3001\u70b9\u51fb\u9875\u9762 OK\n3\u3001\u7b49\u5f85\u8fdb\u5ea6\u6761\u6267\u884c\u5b8c\u6210\uff0c\u6210\u529f\u8fdb\u5ea6\u6761\u663e\u793a\u7eff\u8272\uff0c\u53cd\u4e4b\u7ea2\u8272\n4\u3001\u751f\u6210\u7684\u6587\u4ef6\u4e0e\u6e90\u6587\u4ef6\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\uff0c\u5e76\u901a\u8fc7\u6e90\u6587\u4ef6\u540d_\u6570\u5b57\u6807\u8bb0");
									textPane2.setEditable(false);
									textPane2.setBackground(new Color(0x00cccc));
									scrollPane3.setViewportView(textPane2);
								}
								panel14.add(scrollPane3);
								scrollPane3.setBounds(15, 10, 805, 170);

								{
									// compute preferred size
									Dimension preferredSize = new Dimension();
									for(int i = 0; i < panel14.getComponentCount(); i++) {
										Rectangle bounds = panel14.getComponent(i).getBounds();
										preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
										preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
									}
									Insets insets = panel14.getInsets();
									preferredSize.width += insets.right;
									preferredSize.height += insets.bottom;
									panel14.setMinimumSize(preferredSize);
									panel14.setPreferredSize(preferredSize);
								}
							}
							panel3.add(panel14);
						}
						toolBar3.add(panel3);
					}
					tabbedPane1.addTab("ESB\u5143\u6570\u636e\u8f6c\u6362", toolBar3);

					//======== toolBar4 ========
					{

						//======== panel5 ========
						{
							panel5.setLayout(new CardLayout());

							//======== tabbedPane2 ========
							{

								//======== toolBar5 ========
								{

									//======== panel6 ========
									{
										panel6.setLayout(new GridLayout(3, 0));

										//======== panel7 ========
										{
											panel7.setLayout(null);

											//---- label5 ----
											label5.setText(" \u8bf7\u9009\u62e9\u6587\u4ef6...");
											label5.setBorder(LineBorder.createBlackLineBorder());
											panel7.add(label5);
											label5.setBounds(25, 30, 660, 40);

											//---- button4 ----
											button4.setText("\u9009\u62e9\u6587\u4ef6");
											panel7.add(button4);
											button4.setBounds(695, 30, 115, 40);
											// TODO change
											button4.addActionListener(new XmlFileChooseListener(label5, chooser));
											
											{
												// compute preferred size
												Dimension preferredSize = new Dimension();
												for(int i = 0; i < panel7.getComponentCount(); i++) {
													Rectangle bounds = panel7.getComponent(i).getBounds();
													preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
													preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
												}
												Insets insets = panel7.getInsets();
												preferredSize.width += insets.right;
												preferredSize.height += insets.bottom;
												panel7.setMinimumSize(preferredSize);
												panel7.setPreferredSize(preferredSize);
											}
										}
										panel6.add(panel7);

										//======== panel15 ========
										{
											panel15.setLayout(new GridLayout(2, 0));

											//======== panel17 ========
											{
												panel17.setLayout(null);

												//---- label7 ----
												label7.setText("\u7ba1\u7406\u7aef\u5730\u5740:");
												panel17.add(label7);
												label7.setBounds(20, 10, 85, 35);
												panel17.add(apolloPortal);
												apolloPortal.setBounds(110, 10, 160, 35);

												//---- label8 ----
												label8.setText("   \u53d1\u5e03\u73af\u5883\uff1a");
												panel17.add(label8);
												label8.setBounds(295, 10, 100, 35);
												panel17.add(apolloEnv);
												apolloEnv.setBounds(400, 10, 145, 35);
												
												{
													// compute preferred size
													Dimension preferredSize = new Dimension();
													for(int i = 0; i < panel17.getComponentCount(); i++) {
														Rectangle bounds = panel17.getComponent(i).getBounds();
														preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
														preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
													}
													Insets insets = panel17.getInsets();
													preferredSize.width += insets.right;
													preferredSize.height += insets.bottom;
													panel17.setMinimumSize(preferredSize);
													panel17.setPreferredSize(preferredSize);
												}
											}
											panel15.add(panel17);

											//======== panel16 ========
											{
												panel16.setLayout(null);
												panel16.add(apolloUsername);
												apolloUsername.setBounds(110, 10, 160, 35);

												//---- label1 ----
												label1.setText("\u7ba1\u7406\u7aef\u8d26\u53f7\uff1a");
												panel16.add(label1);
												label1.setBounds(20, 10, 105, 40);

												//---- label2 ----
												label2.setText("   \u7ba1\u7406\u7aef\u5bc6\u7801\uff1a");
												panel16.add(label2);
												label2.setBounds(295, 10, 100, 35);
												panel16.add(apolloPassword);
												apolloPassword.setBounds(400, 10, 145, 35);
												
												{
													// compute preferred size
													Dimension preferredSize = new Dimension();
													for(int i = 0; i < panel16.getComponentCount(); i++) {
														Rectangle bounds = panel16.getComponent(i).getBounds();
														preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
														preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
													}
													Insets insets = panel16.getInsets();
													preferredSize.width += insets.right;
													preferredSize.height += insets.bottom;
													panel16.setMinimumSize(preferredSize);
													panel16.setPreferredSize(preferredSize);
												}
											}
											panel15.add(panel16);
										}
										panel6.add(panel15);

										//======== scrollPane4 ========
										{

											//---- textPane4 ----
											textPane4.setText("\u6ce8\u610f\u4e8b\u9879\uff1a\n1\u3001\u9002\u7528\u4e8e\u62c6\u7ec4\u5305\u914d\u7f6e\u5bfc\u5165\u914d\u7f6e\u4e2d\u5fc3\n2\u3001\u8d26\u53f7\u4e3a\u63a7\u5236\u53f0\u8d26\u53f7\uff0c\u56e0\u5bc6\u7801\u6d89\u53ca\u52a0\u5bc6\uff0c\u8bf7\u901a\u8fc7\u6d4f\u89c8\u5668F12\u6293\u53d6\u767b\u9646\u63a5\u53e3\u52a0\u5bc6\u540e\u5bc6\u7801\n3\u3001\u7a0b\u5e8f\u4ec5\u8fdb\u884c\u5bfc\u5165\u64cd\u4f5c\uff0c\u6d89\u53ca\u4e0b\u53d1\u52a8\u4f5c\u8bf7\u5230\u63a7\u5236\u53f0\u624b\u52a8\u786e\u8ba4\u4e0b\u53d1\n\n\u4f7f\u7528\u65b9\u6cd5\uff1a\n1\u3001\u5728\u8f93\u5165\u6846\u586b\u5199\u5730\u5740\u3001\u8d26\u53f7\u5bc6\u7801\u7b49\u53c2\u6570\n2\u3001\u70b9\u51fb\u9009\u62e9\u6587\u4ef6\u6309\u94ae\uff0c\u9009\u62e9\u62c6\u7ec4\u5305\u914d\u7f6e\u76ee\u5f55\n3\u3001\u70b9\u51fb\u9875\u9762 OK\uff0c\u5c06\u5f39\u51fa\u62c6\u7ec4\u5305\u9009\u62e9\u5217\u8868\uff0c\u94a9\u9009\u9700\u8981\u8fdb\u884c\u5bfc\u5165\u7684\u6587\u4ef6\n4\u3001\u9009\u62e9APPID\u3001\u63a5\u5165\u534f\u8bae\u3001\u63a5\u51fa\u534f\u8bae\u3001\u670d\u52a1\u6d41\u7a0b\u5e76\u70b9\u51fb\u53d1\u5e03\n5\u3001\u7b49\u5f85\u7a0b\u5e8f\u5bfc\u5165");
											textPane4.setEditable(false);
											textPane4.setBackground(new Color(0x00cccc));
											scrollPane4.setViewportView(textPane4);
										}
										panel6.add(scrollPane4);
									}
									toolBar5.add(panel6);
								}
								tabbedPane2.addTab("ESB\u63a7\u5236\u53f0", toolBar5);
								tabbedPane2.addTab("\u670d\u52a1\u6cbb\u7406\u5e73\u53f0", toolBar6);
							}
							panel5.add(tabbedPane2, "card1");
						}
						toolBar4.add(panel5);
					}
					tabbedPane1.addTab("\u62c6\u7ec4\u5305\u5bfc\u5165\u914d\u7f6e\u4e2d\u5fc3", toolBar4);

					//======== toolBar2 ========
					{

						//======== panel1 ========
						{
							panel1.setLayout(null);

							//======== scrollPane1 ========
							{

								//---- textPane3 ----
								textPane3.setText("\u795e\u5dde\u6570\u7801\u878d\u4fe1\n\nLOGO");
								textPane3.setEditable(false);
								scrollPane1.setViewportView(textPane3);
							}
							panel1.add(scrollPane1);
							scrollPane1.setBounds(10, 10, 835, 355);

							{
								// compute preferred size
								Dimension preferredSize = new Dimension();
								for(int i = 0; i < panel1.getComponentCount(); i++) {
									Rectangle bounds = panel1.getComponent(i).getBounds();
									preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
									preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
								}
								Insets insets = panel1.getInsets();
								preferredSize.width += insets.right;
								preferredSize.height += insets.bottom;
								panel1.setMinimumSize(preferredSize);
								panel1.setPreferredSize(preferredSize);
							}
						}
						toolBar2.add(panel1);
					}
					tabbedPane1.addTab("\u5173\u4e8e\u6211\u4eec", toolBar2);
				}
				contentPanel.add(tabbedPane1, "card1");
			}
			dialogPane.add(contentPanel, BorderLayout.CENTER);

			//======== buttonBar ========
			{
				buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
				buttonBar.setLayout(new GridBagLayout());
				((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};
				((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};
				buttonBar.add(progressBar1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 0, 5), 0, 0));

				//---- okButton ----
				okButton.setText("OK");
				buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 0, 5), 0, 0));
				
				// TODO change
				List<LabelEntity> labels = Arrays.asList(
						new LabelEntity(label3, HandlerType.EXTRACT), 
						new LabelEntity(label4, HandlerType.CONVERT),
						new LabelEntity(label5, HandlerType.CONFIG)
				);
				okButton.addActionListener(new OkOnPressListener(progressBar1, tabbedPane1, labels));
				
				//---- cancelButton ----
				cancelButton.setText("Cancel");
				buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
					GridBagConstraints.CENTER, GridBagConstraints.BOTH,
					new Insets(0, 0, 0, 0), 0, 0));
			}
			dialogPane.add(buttonBar, BorderLayout.SOUTH);
		}
		contentPane.add(dialogPane, BorderLayout.CENTER);
		pack();
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
	private JPanel dialogPane;
	private JPanel contentPanel;
	private JTabbedPane tabbedPane1;
	private JToolBar toolBar1;
	private JPanel panel2;
	private JPanel panel11;
	private JButton button2;
	private JFileChooser chooser;	// TODO change
	private JLabel label3;
	private JPanel panel12;
	private JScrollPane scrollPane2;
	private JTextPane textPane1;
	private JToolBar toolBar3;
	private JPanel panel3;
	private JPanel panel13;
	private JButton button3;
	private JLabel label4;
	private JPanel panel14;
	private JScrollPane scrollPane3;
	private JTextPane textPane2;
	private JToolBar toolBar4;
	private JPanel panel5;
	private JTabbedPane tabbedPane2;
	private JToolBar toolBar5;
	private JPanel panel6;
	private JPanel panel7;
	private JLabel label5;
	private JButton button4;
	private JPanel panel15;
	private JPanel panel17;
	private JLabel label7;
	public JTextField apolloPortal;
	private JLabel label8;
	public JTextField apolloEnv;
	private JPanel panel16;
	public JTextField apolloUsername;
	private JLabel label1;
	private JLabel label2;
	public JPasswordField apolloPassword;
	private JScrollPane scrollPane4;
	private JTextPane textPane4;
	private JToolBar toolBar6;
	private JToolBar toolBar2;
	private JPanel panel1;
	private JScrollPane scrollPane1;
	private JTextPane textPane3;
	private JPanel buttonBar;
	private JProgressBar progressBar1;
	private JButton okButton;
	private JButton cancelButton;
	// JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
